主题
PivotItems (对象)
数据透视表字段中所有 PivotItem 对象的集合。
说明
这些项目是某个字段类型中的各个数据项。
使用 PivotItems 方法可返回 PivotItems 集合。
示例
python
#本示例为 Sheet1 上第一张数据透视表创建那些字段中包含的字段名和项目的枚举列表
def test():
Worksheets.Item("Sheet2").Activate()
pTab = Worksheets.Item("Sheet1").PivotTables(1)
c = 1
for i in range(1, pTab.PivotFields().Count):
r = 1
Cells.Item(r, c).Value2 = pTab.PivotFields(i).Name
r = r + 1
for x in range(1, pTab.PivotFields(i).PivotItems().Count):
Cells.Item(r, c).Value2 = pTab.PivotFields(i).PivotItems(x).Name
r = r + 1
c = c + 1
使用 PivotItems (index)(其中 index 是项目索引号或名称)可返回一个 PivotItem 对象。
python
#此示例隐藏工作表 Sheet1 中第一张数据透视表的字段“id”的数据项“4”
def test():
pvtItems = Worksheets.Item("sheet1").PivotTables(1).PivotFields("id").PivotItems()
pvtItems.Item("4").Visible = False